package main

import (
	"fmt"
	"whoscored/util/httputil"
	"strings"
	"github.com/boltdb/bolt"

	"whoscored/util/boltdb"

)

/**
抓取比赛
 */
func fetchPlayerFailed(dbKey string,bucket,id string)  {

	url:="http://mapi01.whoscored.com/Matches/Show/"+id
	fmt.Println(url)
	headers:=map[string]string{

	}
	data:=httputil.Request(url,"GET",headers,nil,)
	//fmt.Println(data)
	if !strings.Contains(data,"info"){
		boltdb.Put("failedPlayer2",bucket,id,"1")
		return
	}

	boltdb.Put(dbKey,bucket,id,data)
}

func main()  {

	boltdb.ScanTx("failedPlayer", func(tx *bolt.Tx) {

		tx.ForEach(func(name []byte, b *bolt.Bucket) error {

			b.ForEach(func(k, v []byte) error {
				fetchPlayerFailed("player",string(name),string(k))
				return nil
			})
			return nil
		})
	})

}
